package service

import (
	"context"
	"github.com/go-kratos/kratos/v2/log"
	"hello-kratos/kratos-server/api/v1"
	"hello-kratos/kratos-server/internal/biz"
)

type UserService struct {
	v1.UnimplementedUserServer
	l  *log.Helper
	uc *biz.UserUseCase
}

func NewUserService(uc *biz.UserUseCase, logger log.Logger) *UserService {
	return &UserService{
		uc: uc,
		l:  log.NewHelper(logger),
	}
}

func (s *UserService) FindUserForLogin(ctx context.Context, req *v1.FindUserForLoginRequest) (*v1.FindUserForLoginResponse, error) {
	user, err := s.uc.FindForLogin(ctx, &biz.User{
		UserName: req.GetUsername(),
		PassWord: req.GetPassword(),
	})
	if err != nil {
		return nil, err
	}
	return &v1.FindUserForLoginResponse{
		Id:       user.Id,
		Account:  user.Account,
		Username: user.UserName,
		Password: user.PassWord,
		Nickname: user.NickName,
		Age:      user.Age,
		Gender:   user.Gender,
		Remark:   user.Remark,
	}, nil
}
